package array

import (
	"sort"
	"strings"
)

func FrequencySort(s string) string {

	str_list := strings.Split(s, "")
	set := []string{}
	freMap := map[string]int{}

	for _, v := range str_list {
		if _, ok := freMap[v]; ok {
			freMap[v]++
		} else {
			freMap[v] = 1
			set = append(set, v)
		}
	}

	sort.Slice(set, func(i, j int) bool {
		return freMap[set[i]] > freMap[set[j]]
	})

	res := ""

	for _, v := range set {
		for i := 0; i < freMap[v]; i++ {
			res += v
		}
	}

	return res
}
